<template>
  <header class="header">
    <h1>todos</h1>
    <input v-model="isAll" id="toggle-all" class="toggle-all" type="checkbox" />
    <label for="toggle-all"></label>
    <input
      @keydown.enter="add"
      v-model="event"
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
    />
  </header>
</template>

<script>
import { mapState, mapGetters, mapMutations } from "vuex";
export default {
  methods: {
    ...mapMutations("flle", ["add", "item"]),
  },
  computed: {
    ...mapState("flle", ["ent", "list"]),
    ...mapGetters("flle", ["isAll"]),
    // 全选切换
    isAll: {
      get() {
        if (this.list.length === 0) return false;
        return this.list.every((item) => item.isDone);
      },
      set(val) {
        this.list.forEach((item) => (item.isDone = val));
      },
    },
    // 检测输入框并传值
    event: {
      get() {
        return;
      },
      set(newVal) {
        this.$store.commit("item", newVal);
        this.item({ newVal });
        // console.log(newVal);
      },
    },
  },
};
</script>